<?php
/**
 * SimplifyPHP Framework
 *
 * This file is part of SimplifyPHP Framework.
 *
 * SimplifyPHP Framework is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * SimplifyPHP Framework is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @author Rodrigo Rutkoski Rodrigues, <rutkoski@gmail.com>
 * @copyright Copyright 2008 Rodrigo Rutkoski Rodrigues
 */

require_once ('HTMLElement.php');

/**
 *
 * @author Rodrigo Rutkoski Rodrigues <rutkoski@gmail.com>
 *
 */
class HtmlHelper extends Helper
{

  protected static $headContent = array();

  public function appendToHead($content)
  {
    self::$headContent[] = $content;
  }

  public function prependToHead($content)
  {
    array_unshift(self::$headContent, $content);
  }

  public function getHeadContent()
  {
    $output = implode("\n", self::$headContent);
    return $this->output($output);
  }

  /**
   *
   * @param $src
   * @param $alt
   * @return unknown_type
   */
  public function image($src, $alt = '', $attribs = null, $params = null)
  {
    global $config;

    if (! sy_url_is_absolute($src)) {
      $src = sy_fix_url($config->get('theme_url') . '/images/' . $src);
    }

    $img = new HTMLElement('img', $attribs, $params);
    $img->attr('src', $src);
    $img->attr('alt', $alt);

    return $this->output($img);
  }

  /**
   *
   * @param $href
   * @return unknown_type
   */
  public function css($href, $attribs = null, $params = null)
  {
    global $config;

    if (! sy_url_is_absolute($href)) {
      $href = sy_fix_url($config->get('theme_url') . '/css/' . $href);
    }

    $href = sy_fix_extension($href, 'css');

    $css = new HTMLElement('link', $attribs, $params);
    $css->attr('href', $href);
    $css->attr('type', "text/css");
    $css->attr('rel', "stylesheet");

    return $this->output($css) . "\n";
  }

  /**
   *
   * @param $href
   * @return unknown_type
   */
  public function link($href, $label, $title = null, $attribs = null, $params = null)
  {
    if (! sy_url_is_absolute($href)) {
      $href = $this->response->makeUrl($href);
    }

    $link = new HTMLElement('a', $attribs, $params, $label);
    $link->attr('href', $href);
    $link->attr('title', $title ? $title : $label);

    return $this->output($link);
  }

}

?>